package com.example.day08.service.impl;

import com.example.day08.dao.EmpMapper;
import com.example.day08.dao.TongMapper;
import com.example.day08.pojo.Emp;
import com.example.day08.pojo.Tong;
import com.example.day08.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private TongMapper tongMapper;

    @Override
    public List<Emp> findAll() {
        List<Emp> list = empMapper.selectList(null);
        return list;
    }

    @Override
    public void add(Emp emp) {
        emp.setCreatetime(new Date());
        empMapper.insert(emp);
    }

    @Override
    public Integer ding() {
        return empMapper.ding();
    }

    @Override
    public void save(Integer a) {
        Tong tong = new Tong();
        tong.setNum(a);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(new Date());
        calendar.add(Calendar.DATE,-1);
        String format = sdf.format(calendar.getTime());
        tong.setCreatetime(format);
        tongMapper.sava(tong);
    }
}
